﻿using UnityEngine;
using UnityEngine.UI;
using System.Collections;

public class BloodBarController : MonoBehaviour {

    public GameObject Player
    {
        get
        {
            if (player == null)
                player = GameObject.FindGameObjectWithTag("Player");
            return player;
        }
    }
    GameObject player;
    SoldierBehaviour sb;
    public UISlider Slider;
    int previousLive;
	// Use this for initialization
	void Start () {
        sb = Player.GetComponent<SoldierBehaviour>();
        previousLive = sb.Life;
        SetLive(sb.Life);
	}
	
	// Update is called once per frame
	void Update () {
        if(sb.Life != previousLive)
        {
            SetLive(sb.Life);
            previousLive = sb.Life;
        }
	}

    void SetLive(int live)
    {
        if(live >= 100)
        {
            Slider.value = 1;
        }
        else if(live >= 0)
        {
            Slider.value = live / 100f;
        }
    }
}
